# !/usr/bin/env python
# -*- coding: utf-8 -*-
"""
@Time        : 2021/10/16 12:28
@Author      : Albert Darren
@Contact     : 2563491540@qq.com
@File        : salt_pepper_noise.py
@Version     : Version 1.0.0
@Description : TODO
@Created By  : PyCharm
"""
from skimage import util
from pydicom import dcmread
from DIP_experiment_5.util import contrast_show
from PIL import ImageFilter, Image
im_path = "../experiment_fig/CT000009"
font_path = "C:/Windows/Fonts/simhei.ttf"
im = dcmread(im_path)
im_arr = im.pixel_array  # 3044 -2000
gray_range = im_arr.max() - im_arr.min()
# 生成椒盐噪声图像数组
salt_pepper_noise = util.random_noise(im_arr, mode='s&p') * gray_range
# 带椒盐噪声的image对象
noise_im = Image.fromarray(salt_pepper_noise).convert("L")
# 5x5最大值滤波器
max_filter_im=noise_im.filter(ImageFilter.MaxFilter(size=5))
# 5x5最小值滤波器
min_filter_im=noise_im.filter(ImageFilter.MinFilter(size=5))
im_dict = {"原始图像": im_arr, "椒盐噪声图像": salt_pepper_noise, "5x5最大值滤波图像": max_filter_im,
           "5x5最小值滤波图像": min_filter_im}
contrast_show(im_dict, (2, 2), hspace=0.4, font=font_path)
# # 5x5均值滤波
# blur_im = noise_im.filter(ImageFilter.BLUR)
# # 5x5高斯滤波
# gaussian_blur_im = noise_im.filter(ImageFilter.GaussianBlur(5))
# # 5x5中值滤波
# median_blur_im = noise_im.filter(ImageFilter.MedianFilter(size=5))

